// To parse this JSON data, do
//
//     final welcome = articleRespFromJson(jsonString);

import 'dart:convert';

HomeArticleResp articleRespFromJson(String str) => HomeArticleResp.fromJson(json.decode(str));

String articleRespToJson(HomeArticleResp data) => json.encode(data.toJson());

class HomeArticleResp {
    ArticleDatas data;
    int errorCode;
    String errorMsg;

    HomeArticleResp({
        required this.data,
        required this.errorCode,
        required this.errorMsg,
    });

    factory HomeArticleResp.fromJson(Map<String, dynamic> json) => HomeArticleResp(
        data: ArticleDatas.fromJson(json["data"]),
        errorCode: json["errorCode"],
        errorMsg: json["errorMsg"],
    );

    Map<String, dynamic> toJson() => {
        "data": data.toJson(),
        "errorCode": errorCode,
        "errorMsg": errorMsg,
    };
}

class ArticleDatas {
    int curPage;
    List<ArticleItemData> datas;
    int offset;
    bool over;
    int pageCount;
    int size;
    int total;

    ArticleDatas({
        required this.curPage,
        required this.datas,
        required this.offset,
        required this.over,
        required this.pageCount,
        required this.size,
        required this.total,
    });

    factory ArticleDatas.fromJson(Map<String, dynamic> json) => ArticleDatas(
        curPage: json["curPage"],
        datas: List<ArticleItemData>.from(json["datas"].map((x) => ArticleItemData.fromJson(x))),
        offset: json["offset"],
        over: json["over"],
        pageCount: json["pageCount"],
        size: json["size"],
        total: json["total"],
    );

    Map<String, dynamic> toJson() => {
        "curPage": curPage,
        "datas": List<dynamic>.from(datas.map((x) => x.toJson())),
        "offset": offset,
        "over": over,
        "pageCount": pageCount,
        "size": size,
        "total": total,
    };
}

class ArticleItemData {
    bool adminAdd;
    String apkLink;
    int audit;
    String author;
    bool canEdit;
    int chapterId;
    String chapterName;
    bool collect;
    int courseId;
    String desc;
    String descMd;
    String envelopePic;
    bool fresh;
    String host;
    int id;
    bool isAdminAdd;
    String link;
    String niceDate;
    String niceShareDate;
    String origin;
    String prefix;
    String projectLink;
    int publishTime;
    int realSuperChapterId;
    int selfVisible;
    int shareDate;
    String shareUser;
    int superChapterId;
    // Name superChapterName;
    String superChapterName;
    List<Tag?> tags;
    String title;
    int type;
    int userId;
    int visible;
    int zan;

    ArticleItemData({
        required this.adminAdd,
        required this.apkLink,
        required this.audit,
        required this.author,
        required this.canEdit,
        required this.chapterId,
        required this.chapterName,
        required this.collect,
        required this.courseId,
        required this.desc,
        required this.descMd,
        required this.envelopePic,
        required this.fresh,
        required this.host,
        required this.id,
        required this.isAdminAdd,
        required this.link,
        required this.niceDate,
        required this.niceShareDate,
        required this.origin,
        required this.prefix,
        required this.projectLink,
        required this.publishTime,
        required this.realSuperChapterId,
        required this.selfVisible,
        required this.shareDate,
        required this.shareUser,
        required this.superChapterId,
        required this.superChapterName,
        required this.tags,
        required this.title,
        required this.type,
        required this.userId,
        required this.visible,
        required this.zan,
    });

    factory ArticleItemData.fromJson(Map<String, dynamic> json) => ArticleItemData(
        adminAdd: json["adminAdd"],
        apkLink: json["apkLink"],
        audit: json["audit"],
        author: json["author"],
        canEdit: json["canEdit"],
        chapterId: json["chapterId"],
        chapterName: json["chapterName"],
        collect: json["collect"],
        courseId: json["courseId"],
        desc: json["desc"],
        descMd: json["descMd"],
        envelopePic: json["envelopePic"],
        fresh: json["fresh"],
        host: json["host"],
        id: json["id"],
        isAdminAdd: json["isAdminAdd"],
        link: json["link"],
        niceDate: json["niceDate"],
        niceShareDate: json["niceShareDate"],
        origin: json["origin"],
        prefix: json["prefix"],
        projectLink: json["projectLink"],
        publishTime: json["publishTime"],
        realSuperChapterId: json["realSuperChapterId"],
        selfVisible: json["selfVisible"],
        shareDate: json["shareDate"],
        shareUser: json["shareUser"],
        superChapterId: json["superChapterId"],
        // superChapterName: nameValues.map[json["superChapterName"]]!,
        superChapterName: json["superChapterName"],
        tags: List<Tag>.from(json["tags"].map((x) => Tag.fromJson(x))),
        title: json["title"],
        type: json["type"],
        userId: json["userId"],
        visible: json["visible"],
        zan: json["zan"],
    );

    Map<String, dynamic> toJson() => {
        "adminAdd": adminAdd,
        "apkLink": apkLink,
        "audit": audit,
        "author": author,
        "canEdit": canEdit,
        "chapterId": chapterId,
        "chapterName": chapterName,
        "collect": collect,
        "courseId": courseId,
        "desc": desc,
        "descMd": descMd,
        "envelopePic": envelopePic,
        "fresh": fresh,
        "host": host,
        "id": id,
        "isAdminAdd": isAdminAdd,
        "link": link,
        "niceDate": niceDate,
        "niceShareDate": niceShareDate,
        "origin": origin,
        "prefix": prefix,
        "projectLink": projectLink,
        "publishTime": publishTime,
        "realSuperChapterId": realSuperChapterId,
        "selfVisible": selfVisible,
        "shareDate": shareDate,
        "shareUser": shareUser,
        "superChapterId": superChapterId,
        // "superChapterName": nameValues.reverse[superChapterName],
        "superChapterName": superChapterName,
        "tags": List<dynamic>.from(tags.map((x) => x?.toJson())),
        "title": title,
        "type": type,
        "userId": userId,
        "visible": visible,
        "zan": zan,
    };
}

enum Name {
    EMPTY,
    NAME,
    TAB
}

final nameValues = EnumValues({
    "技术周报": Name.EMPTY,
    "公众号": Name.NAME,
    "广场Tab": Name.TAB
});

class Tag {
    // Name name;
    String name;
    String url;

    Tag({
        required this.name,
        required this.url,
    });

    factory Tag.fromJson(Map<String, dynamic> json) => Tag(
        // name: nameValues.map[json["name"]]!,
        name: json['name'],
        url: json["url"],
    );

    Map<String, dynamic> toJson() => {
        // "name": nameValues.reverse[name],
        "name": name,
        "url": url,
    };
}

class EnumValues<T> {
    Map<String, T> map;
    late Map<T, String> reverseMap;

    EnumValues(this.map);

    Map<T, String> get reverse {
            reverseMap = map.map((k, v) => MapEntry(v, k));
            return reverseMap;
    }
}
